import request from '../utils/request';
import { API } from '../utils/config';

/**
 * 获取优惠券列表
 * @param params 查询参数
 * @returns 返回优惠券列表数据
 */
export const getCouponList = (params?: any) => {
  return request({
    url: `${API.CLASSES}/Coupon`,
    method: 'GET',
    params: {
      order: '-createdAt',
      ...params
    }
  });
};

/**
 * 创建优惠券
 * @param data 优惠券数据
 */
export const createCoupon = (data: any) => {
  return request({
    url: `${API.CLASSES}/Coupon`,
    method: 'POST',
    data
  });
};

/**
 * 更新优惠券
 * @param id 优惠券ID
 * @param data 优惠券数据
 */
export const updateCoupon = (id: string, data: any) => {
  return request({
    url: `${API.CLASSES}/Coupon/${id}`,
    method: 'PUT',
    data
  });
};

/**
 * 删除优惠券
 * @param id 优惠券ID
 */
export const deleteCoupon = (id: string) => {
  return request({
    url: `${API.CLASSES}/Coupon/${id}`,
    method: 'DELETE'
  });
};

/**
 * 获取优惠券详情
 * @param id 优惠券ID
 */
export const getCouponDetail = (id: string) => {
  return request({
    url: `${API.CLASSES}/Coupon/${id}`,
    method: 'GET'
  });
};

/**
 * 更新优惠券状态
 * @param id 优惠券ID
 * @param status 状态值
 */
export const updateCouponStatus = (id: string, status: number) => {
  return request({
    url: `${API.CLASSES}/Coupon/${id}`,
    method: 'PUT',
    data: { status }
  });
};

/**
 * 获取用户已领取的优惠券
 * @param customerId 用户ID
 */
export const getCustomerCoupons = (customerId: string) => {
  return request({
    url: `${API.CLASSES}/CustomerCoupon`,
    method: 'GET',
    params: {
      where: JSON.stringify({ customerId: { __type: 'Pointer', className: 'Customer', objectId: customerId } }),
      include: 'couponId'
    }
  });
}; 